<template>
  <div class="register-area" data-info="自动结算">
    <el-button class="next" @click="handleNext" type="primary">
      下一步{{ stepInfo }}
    </el-button>

    <div class="step-comps-area" data-info="具体的业务">
      <component
        :is="curCompName"
        @handleSure="handleSure"
        inputTitle="诊疗项首字母："
      >
         <p  class="middle item">请输入诊疗项<span class="labelColor">首字母</span>进行查询</p> 
      </component>
    </div>
    <!--底部操作-->
    <PatientNumberOperate   :key="widget" @handleBack="handlePre" :time="120000" />
  </div>
</template>

<script>
import PatientNumberOperate from "@sc/DRCbiz/comps/patientNumberOperate/index.vue";
import InputLetterKeyboard from "@sc/DRCbiz/comps/input-letter-keyboard/index.vue";
import ItemList from "@sc/DRCbiz/comps/Item-list/index.vue";
import { v4 as uuid } from "uuid";
import { AndroidToWeb, buildParentApi } from "@/utils/designer/util";
let buildParent = buildParentApi();
export default {
  name: "DrugInformationInquiry",

  componentName: "DrugInformationInquiry",

  components: {
    PatientNumberOperate,
    InputLetterKeyboard,
    ItemList
  },

  data() {
    return {
        widget: uuid(),
      steps: 1,
      curCompName: "CardType",
      compsOptions: {
        1: "InputLetterKeyboard",
        2: "ItemList"
      },
    };
  },

  computed: {
    shownOperate() {
      return this.steps !== 1;
    },
    patientInfo() {
      return this.$store.getters["DRCbiz/getPatientInfo"];
    },
    // 步骤
    stepInfo() {
      return this.$store.getters["DRCbiz/getStepsInfo"];
    },
    //选中的卡片信息
    cardTypeInfo() {
      return this.$store.getters['DRCbiz/getCardTypeInfo']
    },
  },

  mounted() {
    this.$store.dispatch("DRCbiz/setCTDTimeInfo", 1200000);
  },

  methods: {
 
    handleSure(input) {
       let devInfo = JSON.parse(localStorage.getItem("deviceInfo"));
           // {"result":[
          //   {"itemCode":"5579",
          //   "itemName":"前臂尺神经探查吻合术",
          //   "specifications":"",
          //   "price":"162000",
          //   "priceUnit":"次",
          //   "producer":"",
          //   "type":"手术及麻醉费",
          //   "chargelevel":"甲",
          //   "insurancecode":"003315210360300"},
          //   {"itemCode":"6276",
          //   "itemName":"浅表腹壁肿瘤切除术",
          //   "specifications":"",
          //   "price":"36000",
          //   "priceUnit":"次",
          //   "producer":"",
          //   "type":"手术及麻醉费",
          //   "chargelevel":"甲",
          //   "insurancecode":"003310080170000"
          //   }]}
          let QueryCostInfoParams = {
            Request: {
              deviceIp: devInfo.screenIp,
              flowId: uuid(),
              timestamp: this.$day().valueOf(),
              terminalNo: devInfo?.screenId, // 自助机设备终端	C	可空	根据医院实际情况
              method: "QueryCostInfo",
              pinyinCode: input,
            },
          };
     
          let QueryParams = this.$x2js.js2xml(QueryCostInfoParams);
          buildParent.executeParentMethod(
            "axiosRep",
            QueryParams,
            "QueryCostInfo"
          );
    },
    async handleNext() {
       let stepInfo = parseInt(this.stepInfo);
      this.widget = uuid();
      if (stepInfo === 2) {
        await this.$store.dispatch("DRCbiz/setStepsInfo", 1);
      } else {
        await this.$store.dispatch("DRCbiz/setStepsInfo", ++stepInfo);
      }
    },

    // 返回上一层&首页
    async handlePre() {
      this.widget = uuid();
      let stepInfo = parseInt(this.stepInfo);
      if (stepInfo === 1) {
        await this.$router.push({
          path: `/DRCbizList`,
        });
      } else {
        await this.$store.dispatch("DRCbiz/setStepsInfo", --stepInfo);
      }
      switch (parseInt(this.stepInfo)) {
        case 2:
          let cardTypeInfo = this.cardTypeInfo;
          Reflect.set(cardTypeInfo, "cardNo", null);
          await this.$store.dispatch("DRCbiz/setCardTypeInfo", cardTypeInfo);
          buildParent.executeParentMethod("openScan");
          break;
      }
    },
  },

  watch: {
     // 步距
    stepInfo: {
      handler: function (val) {
        const self = this;
        self.widget = uuid();
        let cardTypeInfo = self.cardTypeInfo;
        if ( cardTypeInfo && val === 2) {
          // 电子医保特殊处理
          if (parseInt(cardTypeInfo?.id) === 29) {
            buildParent.executeParentMethod("MICode");
          } else {
            buildParent.executeParentMethod("openScan");
          }
        } else {
          buildParent.executeParentMethod("closeScan");
        }
        
        self.curCompName = Reflect.get(self.compsOptions, val);

      },
      deep: true,
      immediate: true,
    },
  },
};
</script>

<style scoped lang="scss">
@import "./assets/style";
</style>